// import 'dart:async';

import 'package:flutter/material.dart';
import 'package:get/get.dart';
 import './tabs/home.dart';
//import './tabs/home_web.dart';
import './tabs/communication.dart';
import './tabs/square.dart';
import './tabs/find.dart';
import './tabs/property.dart';

import './web_tabs/market.dart';
import './web_tabs/pledge.dart';
import './web_tabs/assets.dart';

import '../controllers/web3.dart';


final RxInt _currentIndex = 0.obs;

class Tabs extends GetView<WebController> {

 
  
  Tabs({super.key});

  @override
  Widget build(BuildContext context) {

    // _currentIndex.value = Get.arguments['index']??0;



    final RxBool WEB = controller.isweb;

    final List<Widget> _pages = [
      HomePage(),
      Obx(() => WEB.value ? Market() : CommunicationLIst()),
      Obx(
        () => WEB.value ? Pledge() : SquareLIst(),
      ),
      Obx(
        () => WEB.value ? SizedBox()
        : FindLIst(),
      ),
      Obx(
        () => WEB.value ? Assets() : PropertyLIst(),
      ),
    ];

    return Scaffold(
        body:Obx(() => _pages[_currentIndex.value]),
        bottomNavigationBar: Obx(() => WEB.value ? navTabsWeb3() : navTabs()));
  }
}

Widget navTabs() {
  // Map<String, Object> myList = {'id':2,'uder':'655'};

  //   Get.find<MyMethod>().myset('user', myList);

  // Timer(Duration(seconds: 5), () {

  //  Get.find<MyMethod>().myget('user');

  // print(Get.find<MyMethod>().isweb['id']);

  // });

  return BottomNavigationBar(
      fixedColor: Color(0xff6A3BD9), //选中的颜色
      backgroundColor: Color(0xffffffff),
      currentIndex: _currentIndex.value, //第几个菜单选中
      type: BottomNavigationBarType.fixed, //如果底部有4个或者4个以上的菜单的时候就需要配置这个参数
      onTap: (index) {
        //点击菜单触发的方法
        //注意
        _currentIndex.value = index;
        print(index);
      },
      items: [
        BottomNavigationBarItem(
            icon: Image(
              image: AssetImage(_currentIndex.value == 0
                  ? "static/images/tabs/jianxuns.png"
                  : "static/images/tabs/jianxun.png"),
              width: 30,
            ),
            label: "简讯"),
        BottomNavigationBarItem(
            icon: Image(
              image: AssetImage(_currentIndex.value == 1
                  ? "static/images/tabs/tongxunlus.png"
                  : "static/images/tabs/tongxunlu.png"),
              width: 30,
            ),
            label: "通讯录"),
        BottomNavigationBarItem(
            icon: Image(
              image: AssetImage(_currentIndex.value == 2
                  ? "static/images/tabs/guangchangs.png"
                  : "static/images/tabs/guangchang.png"),
              width: 30,
            ),
            label: "广场"),
        BottomNavigationBarItem(
            icon: Image(
              image: AssetImage(_currentIndex.value == 3
                  ? "static/images/tabs/faxians.png"
                  : "static/images/tabs/faxian.png"),
              width: 30,
            ),
            label: "发现"),
        BottomNavigationBarItem(
            icon: Image(
              image: AssetImage(_currentIndex.value == 4
                  ? "static/images/tabs/wodes.png"
                  : "static/images/tabs/wode.png"),
              width: 30,
            ),
            label: "我的"),
      ]);
}

Widget navTabsWeb3() {
  return BottomNavigationBar(
      fixedColor: Color(0xff0F172B), //选中的颜色
      backgroundColor: Color(0xffffffff),
      currentIndex: _currentIndex.value, //第几个菜单选中
      type: BottomNavigationBarType.fixed, //如果底部有4个或者4个以上的菜单的时候就需要配置这个参数
      onTap: (index) {
        //点击菜单触发的方法
        //注意
      if(index == 3){
       Get.toNamed('/web_webview?url=https://test.cg-online.cn/ZGYH/index.html');
        return;
      }
        _currentIndex.value = index;
       
      },
      items: [
        BottomNavigationBarItem(
            icon: Image(
              image: AssetImage(_currentIndex.value == 0
                  ? "static/web/tabs/homes.png"
                  : "static/web/tabs/home.png"),
              width: 30,
            ),
            label: "首页"),
        BottomNavigationBarItem(
            icon: Image(
              image: AssetImage(_currentIndex.value == 1
                  ? "static/web/tabs/markets.png"
                  : "static/web/tabs/market.png"),
              width: 30,
            ),
            label: "市场"),
        BottomNavigationBarItem(
            icon: Image(
              image: AssetImage(_currentIndex.value == 2
                  ? "static/web/tabs/zhiyas.png"
                  : "static/web/tabs/zhiya.png"),
              width: 30,
            ),
            label: "质押"),
        BottomNavigationBarItem(
            icon: Image(
              image: AssetImage(_currentIndex.value == 3
                  ? "static/web/tabs/shijies.png"
                  : "static/web/tabs/shijie.png"),
              width: 30,
            ),
            label: "世界"),
        BottomNavigationBarItem(
            icon: Image(
              image: AssetImage(_currentIndex.value == 4
                  ? "static/web/tabs/zichans.png"
                  : "static/web/tabs/zichan.png"),
              width: 30,
            ),
            label: "资产"),
      ]);
}
